import util from "./util.js";

/**
 * 获取元素高度 
 * @param {object} that 元素所在页面this
 * @param {string} select 元素选择器 
 */
function getElementHeight(that, select) {
	return new Promise((resolve, reject) => {
		const query = uni.createSelectorQuery().in(that);
		query.select(select).boundingClientRect(data => {
			resolve(data.height);
		}).exec();
	});
}

/**
 * 图片预览
 * @param {Array} file_path_array 图片文件路径
 * @param {Number} current_index 显示图片的链接/索引值
 */
function previewImage(file_path_array, current_index) {
	const tempImgPaths = [];
	
	file_path_array.forEach(item => { // 图片路径处理
		tempImgPaths.push(util.fnImgPath(item));
	});

	uni.previewImage({
		urls: tempImgPaths,
		current: current_index,
		indicator: 'default',
		loop: true,
		fail: res => { // 异常处理
			uni.showToast({
				title: '加载失败',
				icon: 'none',
				duration: 1500
			});
		}
	});

}

export default {
	getElementHeight,
	previewImage
}
